package com.nodusk.result;



import java.util.List;


public class Result<T> {
  private Integer code;
  
  private String msg;
  
  private  T data;
  
  private long count;
  
  private T oneData;
  
  private long dataCount;
  
  private String enmessage;
  public static Result delete( int totalRecords) {
   return delete(null,  totalRecords);
  }
  public Result (){

  }
  public Result (T data){
    this.data=data;
  }
  public static Result delete(Result result, int totalRecords) {
    if(result==null){
      result=new Result();
    }
    if (totalRecords > 0) {
      result.setCode(Integer.valueOf(0));
      result.setDataCount(totalRecords);
      result.setMsg("删除成功");
    } else {
      result.setCode(Integer.valueOf(7));
      result.setMsg("删除失败");
    } 
    return result;
  }
  public static Result insert( int totalRecords) {
    return insert(null,totalRecords);
  }
  public static Result insert(Result result, int totalRecords) {
    if(result==null){
      result=new Result();
    }
    if (totalRecords > 0) {
      result.setCode(Integer.valueOf(0));
      result.setDataCount(totalRecords);
      result.setMsg("添加记录成功");
    } else {
      result.setCode(Integer.valueOf(7));
      result.setMsg("添加记录失败");
    } 
    return result;
  }
  public static Result update( int totalRecords) {
    return update(null,totalRecords);
  }
  public static Result update(Result result, int totalRecords) {
    if(result==null){
      result=new Result();
    }
    if (totalRecords > 0) {
      result.setCode(Integer.valueOf(0));
      result.setDataCount(totalRecords);
      result.setMsg("修改记录成功");
    } else {
      result.setCode(Integer.valueOf(7));
      result.setMsg("修改记录失败");
    } 
    return result;
  }
  
  public static Result err(Result result, String msg) {
    if(result==null){
      result=new Result();
    }
    result.setCode(Integer.valueOf(7));
    result.setMsg(msg);
    return result;
  }
  public static Result err(Integer code, String msg) {
    Result result=new Result();
    result.setCode(code);
    result.setMsg(msg);
    return result;
  }
  public static Result err(Result result) {
    result.setCode(Integer.valueOf(7));
    result.setMsg("操作失败,未知异常");
    return result;
  }
  
  public static Result err(String msg) {
    Result result = new Result();
    result.setCode(Integer.valueOf(7));
    result.setMsg(msg);
    return result;
  }

  public static Result succeed(List o) {
    Result result = new Result();
    result.setData(o);
    result.setCode(Integer.valueOf(0));
    result.setMsg("成功");
    return result;
  }
  
  public static Result succeed(Object o) {
    Result<Object> result = new Result();
    result.setOneData(o);
    result.setCode(Integer.valueOf(0));
    result.setMsg("成功");
    return result;
  }
  
  public static Result err(Result result, String msg, Integer code) {
    result.setMsg(msg);
    result.setCode(code);
    return result;
  }
  
  public void succeedSelect(T list) {
    this.data = list;

    this.msg = "查询成功";
    this.code = Integer.valueOf(0);
  }

  public Integer getCode() {
    return code;
  }

  public void setCode(Integer code) {
    this.code = code;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  public T getData() {
    return data;
  }

  public void setData(T data) {
    this.data = data;
  }

  public long getCount() {
    return count;
  }

  public void setCount(long count) {
    this.count = count;
  }

  public T getOneData() {
    return oneData;
  }

  public void setOneData(T oneData) {
    this.oneData = oneData;
  }

  public long getDataCount() {
    return dataCount;
  }

  public void setDataCount(long dataCount) {
    this.dataCount = dataCount;
  }

  public String getEnmessage() {
    return enmessage;
  }

  public void setEnmessage(String enmessage) {
    this.enmessage = enmessage;
  }
}
